package compress;

import priv.dengjl.compress.util.CompressUtil;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class CompressTest4 {


	public static byte[] generateString() throws Exception {
		File file = new File("data/100MBData.txt");
		byte[] bytes = new byte[(int) file.length()];
		InputStream fis = new FileInputStream(file);
		BufferedInputStream bis = new BufferedInputStream(fis);
		int len = 0;
		int count =0;
		while((len = bis.read()) != -1) {

			bytes[count] = (byte) len;
			count++;
		}
		bis.close();
		return bytes;
	}

	public static void main(String[] args) throws Exception {


		byte[] dataBytes = generateString();
		//System.out.println("压缩前数据大小：" + dataBytes.length);
		
		CompressUtil[] values = CompressUtil.values();
		for (CompressUtil compressUtil : values) {
			System.out.println("===================: " + compressUtil.name());
			long start = System.currentTimeMillis();
			byte[] resultBytes = compressUtil.compress(dataBytes);
			System.out.println("压缩后数据大小:" + resultBytes.length);
			System.out.println("压缩时间(ms)：" + (System.currentTimeMillis() - start));
			long start2 = System.currentTimeMillis();
			byte[] uncompressBytes = compressUtil.uncompress(resultBytes);
			System.out.println("解压后数据大小：" + uncompressBytes.length);
			String result = new String(uncompressBytes);
			System.out.println("解压时间(ms)：" + (System.currentTimeMillis() - start2));
			System.out.println("===================: " + compressUtil.name());
		}
	}

}
